<?php
namespace app\common\controller;

/**
 * 工具类
 * Created by PhpStorm.
 * User: tyll
 * Date: 2018/09/25
 * Time: 16:32
 */
class Tools{

    /**
     * post发送数据
     * @param $url
     * @param $post_data
     * @return mixed
     */
    public function PostuseCurl($url,$post_data) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
        ));
        $result = curl_exec($curl);
        curl_close($curl);
        return $result;
    }

    /**
     * get发送数据
     * @param $url
     * @return mixed
     */
    public function GetuseCurl($url) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($curl);
        curl_close($curl);
        return $result;
    }
}